package com.scsj.supermarket.presenter;

import android.content.Context;
import android.util.Log;

import com.orhanobut.logger.Logger;
import com.scsj.supermarket.base.IndexBase;
import com.scsj.supermarket.base.MarketBase;
import com.scsj.supermarket.bean.BaseBean;
import com.scsj.supermarket.bean.MarketCouPounBean;
import com.scsj.supermarket.bean.MarketDetailBean;
import com.scsj.supermarket.bean.MarketIsOpen;
import com.scsj.supermarket.bean.MarketLeftBean;
import com.scsj.supermarket.bean.MarketRightBean;
import com.scsj.supermarket.bean.MarketShopCarBean;
import com.scsj.supermarket.bean.MarketTopBean;
import com.scsj.supermarket.bean.ShopCarBean;
import com.scsj.supermarket.model.IndexModel;
import com.scsj.supermarket.model.MarketModel;

import dkmvp.mvp.BasePresenter;
import dkmvp.net.ResponseCallback;
import okhttp3.RequestBody;

/**
 * 店铺
 */

public class MarketPresenter extends BasePresenter implements MarketBase.IPresenter {

    private MarketBase.IModel mModel;
    private MarketBase.IView mView;

    public MarketPresenter(MarketBase.IView view) {
        mView = view;
        mModel = new MarketModel();
    }

    /**
     * 店铺内购物车商品
     *
     * @param requestBody
     */
    @Override
    public void deliverMarketShopCarList(RequestBody requestBody) {
        addSubscription(mModel.getMarketShopCarData(requestBody, new ResponseCallback<MarketShopCarBean>() {
            @Override
            public void onSuccess(MarketShopCarBean result) {

                if (result.getStatusCode() == 200) {

                    mView.showSuccessMsg("店铺内购物车数据拿到了，sb");
                    mView.setMarketShopCarData(result);

                } else {
                    mView.showErrorMsg("数据失败了获取"+result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg("数据失败了获取"+msg);
                Log.e("onFaild", msg + "");
            }
        }));
    }

    /**
     * 店铺内购物车加减
     *
     * @param requestBody
     */
    @Override
    public void deliverControlMarketShopcarList(RequestBody requestBody) {
        addSubscription(mModel.getControlMarketShopCarData(requestBody, new ResponseCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean result) {

                if (result.getStatusCode() == 200) {
                    mView.showSuccessMsg("……………………店铺内购物车加减成功………………");
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("onFaild", msg + "");
            }
        }));
    }

    /**
     * 店铺内优惠券
     *
     * @param requestBody
     */
    @Override
    public void deliverMarketCoupounList(RequestBody requestBody) {
        addSubscription(mModel.getMarketCoupounData(requestBody, new ResponseCallback<MarketCouPounBean>() {
            @Override
            public void onSuccess(MarketCouPounBean result) {

                if (result.getStatusCode() == 200) {
                    mView.showSuccessMsg("店铺内优惠券数据拿到了，sb");
                    mView.setMarketCoupounData(result);

                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("onFaild", msg + "");
            }
        }));
    }

    /**
     * 店铺左侧列表数据
     *
     * @param requestBody
     */
    @Override
    public void deliverMarketDetailList(final RequestBody requestBody) {
        addSubscription(mModel.getMarketDetailData(requestBody, new ResponseCallback<MarketDetailBean>() {
            @Override
            public void onSuccess(MarketDetailBean result) {

                if (result.getStatusCode() == 200) {
                    mView.showSuccessMsg("店铺左侧数据获取成功喽，sb");
                    mView.setMarketDetailData(result);
                    Logger.e("000000000"+result.toString());
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }
            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("onFaild", msg + "");
                Logger.e("6666666666666666666666666666666666"+msg);
            }

        }));
    }

    /**
     * 店铺右侧列表数据
     *
     * @param requestBody
     */
    @Override
    public void deliverMarketRightList(RequestBody requestBody) {
        addSubscription(mModel.getMarketRightData(requestBody, new ResponseCallback<MarketRightBean>() {
            @Override
            public void onSuccess(MarketRightBean result) {

                if (result.getStatusCode() == 200) {
                    mView.showSuccessMsg("店铺右侧数据得到了喽，sb");
                    mView.setMarketRightData(result);
                    Logger.e("店铺右侧数据得到喽喽喽喽");
                } else {
                    mView.showErrorMsg(result.getMsg());
                }

            }
            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("onFaild", msg + "");
            }
        }));
    }
}
